/* datetimepicker init 方法 */
function bootstrapDatetimepicker() {
  var pickers = $('.datetimepicker');
  if (pickers.length) {
      pickers.datetimepicker({
          locale: 'zh-cn',
          sideBySide: true,
          format: 'YYYY-MM-DD H:mm'
      });
  }
}

function showConfirm(title,content,confirm,cancel) {
  $.confirm({
    title:title,
    content: content,
    confirmButtonClass: 'btn-info',
    theme: 'material',
    confirmButton: '确定',
    cancelButton: '取消',
    columnClass: 'col-md-offset-3 col-md-6',
    cancel: function(){
      if(cancel) cancel();
    },
    confirm: function(){
      if(confirm) confirm();
    }
  });
};

/**
 * @param title 标题
 * @param content 内容
 * @param confirm 确定方法
 */
function showAlert(title,content,confirm) {
  $.alert({
    title: (title ? title : false),
    content: content,
    keyboardEnabled: true,
    confirmButton: false,
    autoCloseTime: 3000,
    //closeIcon: true,
    //confirmButton: '关闭',
    //autoClose: 'confirm|3000',
    confirm: function(){
        if(confirm) confirm();
    }
  });
};


/**
 * tab切换
 * data-toggle绑定对应div的id
 * tab-index对应index
 * callBack:回调方法参数为tab-index
 * */
function initNavTab(callback) {
    function showActiveDiv() {
        $.each(li_list, function (index, item) {
            var id = $(item).attr("data-toggle");
            $(item).hasClass("active") ? $(id).show() : $(id).hide();
        });
    }

    var tabIndex = $(".nav-tabs li.active").attr("tab-index");
    if (callback) {
        callback(tabIndex);
    }
    ;

    var li_list = $(".nav-tabs li");

    li_list.click(function () {
        $(this).addClass("active");
        $(this).siblings().removeClass("active");
        showActiveDiv();

        var tabIndex = $(this).attr("tab-index");
        if (callback) {
            callback(tabIndex);
        }
        ;
    });

    showActiveDiv();
}


$(function () {
  bootstrapDatetimepicker();
});
